import React, {useState} from 'react';
import ModalContent from "./ModalContent";
import {createPortal} from "react-dom";

function PortalExample(props) {
    const [showModal, setShowModal] = useState(false);
    return (
        <div>
            <button onClick={() => setShowModal(true)}>使用 portal 展示模态</button>
            {showModal && createPortal(
                <ModalContent onClose={() => setShowModal(false)} />,
                document.body
            )}
        </div>
    );
}

export default PortalExample;